Here is our latest patch to enable the Xen tools to
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 29 Jul 2005 10:34:45 +0000 (10:34 +0000)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 29 Jul 2005 10:34:45 +0000 (10:34 +0000)
build and work with IA64 Xen.
Signed-off-by: Matt Chapman <matthewc@hp.com>
Acked-by: Dan Magenheimer <dan.magenheimer@hp.com>
12 files changed:
tools/libxc/Makefile
tools/libxc/xc.h
tools/libxc/xc_domain.c
tools/libxc/xc_linux_build.c
tools/libxc/xc_load_elf.c
tools/libxc/xc_private.c
tools/libxc/xc_private.h
tools/misc/Makefile
tools/python/xen/lowlevel/xc/xc.c
tools/python/xen/lowlevel/xu/xu.c
tools/python/xen/xend/XendCheckpoint.py
tools/xcs/xcs.h

index 8233fff8e2a2fd5fa1c351d651313146cbadec32..81fcdc27501ee50a2023096c2a55acf6d317ca5c 100644 (file)
@@ -19,18 +19,22 @@ SRCS     += xc_core.c
 SRCS     += xc_domain.c
 SRCS     += xc_evtchn.c
 SRCS     += xc_gnttab.c
-SRCS     += xc_load_aout9.c
 SRCS     += xc_load_bin.c
 SRCS     += xc_load_elf.c
 SRCS     += xc_linux_build.c
-SRCS     += xc_linux_restore.c
-SRCS     += xc_linux_save.c
 SRCS     += xc_misc.c
 SRCS     += xc_physdev.c
 SRCS     += xc_private.c
+ifeq ($(XEN_TARGET_ARCH),ia64)
+SRCS     += xc_ia64_stubs.c
+else
+SRCS     += xc_load_aout9.c
+SRCS     += xc_linux_restore.c
+SRCS     += xc_linux_save.c
+SRCS     += xc_vmx_build.c
 SRCS     += xc_ptrace.c
 SRCS     += xc_ptrace_core.c
-SRCS     += xc_vmx_build.c
+endif
 
 CFLAGS   += -Wall
 CFLAGS   += -Werror
index 97310a21f85f701baaf2b09e656f01f4786a5595..417f3d3c94f8a20bbde2b7dfca1ca6c09164a143 100644 (file)
@@ -27,6 +27,14 @@ typedef int64_t            s64;
 #include <xen/sched_ctl.h>
 #include <xen/acm.h>
 
+#ifdef __ia64__
+#define XC_PAGE_SHIFT           14
+#else
+#define XC_PAGE_SHIFT           12
+#endif
+#define XC_PAGE_SIZE            (1UL << XC_PAGE_SHIFT)
+#define XC_PAGE_MASK            (~(XC_PAGE_SIZE-1))
+
 /*
  *  DEFINITIONS FOR CPU BARRIERS
  */ 
@@ -39,6 +47,11 @@ typedef int64_t            s64;
 #define mb()  __asm__ __volatile__ ( "mfence" : : : "memory")
 #define rmb() __asm__ __volatile__ ( "lfence" : : : "memory")
 #define wmb() __asm__ __volatile__ ( "" : : : "memory")
+#elif defined(__ia64__)
+/* FIXME */
+#define mb()
+#define rmb()
+#define wmb()
 #else
 #error "Define barriers"
 #endif
@@ -462,6 +475,9 @@ void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot,
 int xc_get_pfn_list(int xc_handle, u32 domid, unsigned long *pfn_buf, 
                     unsigned long max_pfns);
 
+int xc_ia64_get_pfn_list(int xc_handle, u32 domid, unsigned long *pfn_buf, 
+                    unsigned int start_page, unsigned int nr_pages);
+
 /*\
  *  GRANT TABLE FUNCTIONS
 \*/ 
index 688dbb970afd792efdc2863749224b9cb2437f79..2b16659e9e88c517cfda2f11798374952752da40 100644 (file)
@@ -264,10 +264,11 @@ int xc_domain_memory_increase_reservation(int xc_handle,
                                           unsigned int mem_kb)
 {
     int err;
+    unsigned int npages = mem_kb / (PAGE_SIZE/1024);
 
     err = do_dom_mem_op(xc_handle, MEMOP_increase_reservation, NULL,
-                        mem_kb / 4, 0, domid);
-    if (err == mem_kb / 4)
+                        npages, 0, domid);
+    if (err == npages)
         return 0;
 
     if (err > 0) {
index b0a14c7cc5f92a56e9cc680de8ad149491c3d547..48cace56473157b31246134661de7a34c01759f1 100644 (file)
@@ -8,7 +8,7 @@
 #define ELFSIZE 32
 #endif
 
-#if defined(__x86_64__)
+#if defined(__x86_64__) || defined(__ia64__)
 #define ELFSIZE 64
 #endif
 
 #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
 #define round_pgdown(_p)  ((_p)&PAGE_MASK)
 
+#ifdef __ia64__
+#define probe_aout9(image,image_size,load_funcs) 1
+#endif
+
 static int probeimageformat(char *image,
                             unsigned long image_size,
                             struct load_funcs *load_funcs)
@@ -258,6 +262,67 @@ static int setup_pg_tables_64(int xc_handle, u32 dom,
 }
 #endif
 
+#ifdef __ia64__
+#include <asm/fpu.h> /* for FPSR_DEFAULT */
+static int setup_guest(int xc_handle,
+                         u32 dom,
+                         char *image, unsigned long image_size,
+                         gzFile initrd_gfd, unsigned long initrd_len,
+                         unsigned long nr_pages,
+                         unsigned long *pvsi, unsigned long *pvke,
+                         unsigned long *pvss, vcpu_guest_context_t *ctxt,
+                         const char *cmdline,
+                         unsigned long shared_info_frame,
+                         unsigned int control_evtchn,
+                         unsigned long flags,
+                         unsigned int vcpus,
+                         unsigned int store_evtchn, unsigned long *store_mfn)
+{
+    unsigned long *page_array = NULL;
+    struct load_funcs load_funcs;
+    struct domain_setup_info dsi;
+    unsigned long start_page;
+    int rc;
+
+    rc = probeimageformat(image, image_size, &load_funcs);
+    if ( rc != 0 )
+        goto error_out;
+
+    memset(&dsi, 0, sizeof(struct domain_setup_info));
+
+    rc = (load_funcs.parseimage)(image, image_size, &dsi);
+    if ( rc != 0 )
+        goto error_out;
+
+    dsi.v_start = round_pgdown(dsi.v_start);
+    dsi.v_end   = round_pgup(dsi.v_end);
+
+    start_page = dsi.v_start >> PAGE_SHIFT;
+    nr_pages = (dsi.v_end - dsi.v_start) >> PAGE_SHIFT;
+    if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL )
+    {
+        PERROR("Could not allocate memory");
+        goto error_out;
+    }
+
+    if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array, start_page, nr_pages) != nr_pages )
+    {
+        PERROR("Could not get the page frame list");
+        goto error_out;
+    }
+
+    (load_funcs.loadimage)(image, image_size, xc_handle, dom, page_array,
+                           &dsi);
+
+    *pvke = dsi.v_kernentry;
+    return 0;
+
+ error_out:
+    if ( page_array != NULL )
+        free(page_array);
+    return -1;
+}
+#else /* x86 */
 static int setup_guest(int xc_handle,
                        u32 dom,
                        char *image, unsigned long image_size,
@@ -557,6 +622,7 @@ static int setup_guest(int xc_handle,
         free(page_array);
     return -1;
 }
+#endif
 
 int xc_linux_build(int xc_handle,
                    u32 domid,
@@ -627,7 +693,11 @@ int xc_linux_build(int xc_handle,
     }
 
     if ( !(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) ||
+#ifdef __ia64__
+       0 )
+#else
          (ctxt->ctrlreg[3] != 0) )
+#endif
     {
         ERROR("Domain is already constructed");
         goto error_out;
@@ -652,6 +722,18 @@ int xc_linux_build(int xc_handle,
     if ( image != NULL )
         free(image);
 
+#ifdef __ia64__
+    /* based on new_thread in xen/arch/ia64/domain.c */
+    ctxt->regs.cr_ipsr = 0; /* all necessary bits filled by hypervisor */
+    ctxt->regs.cr_iip = vkern_entry;
+    ctxt->regs.cr_ifs = 1UL << 63;
+    ctxt->regs.ar_fpsr = FPSR_DEFAULT;
+    /* ctxt->regs.r28 = dom_fw_setup(); currently done by hypervisor, should move here */
+    ctxt->vcpu.privregs = 0;
+    ctxt->shared.domain_controller_evtchn = control_evtchn;
+    ctxt->shared.flags = flags;
+    i = 0; /* silence unused variable warning */
+#else /* x86 */
     /*
      * Initial register values:
      *  DS,ES,FS,GS = FLAT_KERNEL_DS
@@ -706,6 +788,7 @@ int xc_linux_build(int xc_handle,
     ctxt->failsafe_callback_eip = 0;
     ctxt->syscall_callback_eip  = 0;
 #endif
+#endif /* x86 */
 
     memset( &launch_op, 0, sizeof(launch_op) );
 
index 8ee96d5a567ae4bcf6d736aa876440e0e87fb056..926db3a9648f42de1d2b154046a875f5fee30263 100644 (file)
@@ -7,7 +7,7 @@
 #if defined(__i386__)
 #define ELFSIZE 32
 #endif
-#if defined(__x86_64__)
+#if defined(__x86_64__) || defined(__ia64__)
 #define ELFSIZE 64
 #endif
 
@@ -122,8 +122,12 @@ static int parseelfimage(char *image,
     }
     if ( guestinfo == NULL )
     {
+#ifdef __ia64__
+        guestinfo = "";
+#else
         ERROR("Not a Xen-ELF image: '__xen_guest' section not found.");
         return -EINVAL;
+#endif
     }
 
     for ( h = 0; h < ehdr->e_phnum; h++ ) 
index fe8f42c1c81476d7de43a8dea9377ae2d50a1cdb..d05dbe9267e695c00c01cd4bf3dd4a18d9d2e577 100644 (file)
@@ -256,6 +256,37 @@ int xc_get_pfn_list(int xc_handle,
     return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
 }
 
+#ifdef __ia64__
+int xc_ia64_get_pfn_list(int xc_handle,
+                u32 domid, 
+                unsigned long *pfn_buf, 
+                unsigned int start_page,
+                unsigned int nr_pages)
+{
+    dom0_op_t op;
+    int ret;
+
+    op.cmd = DOM0_GETMEMLIST;
+    op.u.getmemlist.domain   = (domid_t)domid;
+    op.u.getmemlist.max_pfns = ((unsigned long)start_page << 32) | nr_pages;
+    op.u.getmemlist.buffer   = pfn_buf;
+
+    if ( mlock(pfn_buf, nr_pages * sizeof(unsigned long)) != 0 )
+    {
+        PERROR("Could not lock pfn list buffer");
+        return -1;
+    }    
+
+    /* XXX Hack to put pages in TLB, hypervisor should be able to handle this */
+    memset(pfn_buf, 0, nr_pages * sizeof(unsigned long));
+    ret = do_dom0_op(xc_handle, &op);
+
+    (void)munlock(pfn_buf, nr_pages * sizeof(unsigned long));
+
+    return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
+}
+#endif
+
 long xc_get_tot_pages(int xc_handle, u32 domid)
 {
     dom0_op_t op;
index 2dd588ea780f8156cc4731ae6ae655003913100b..1b58b0d5231e976e705cbdf22a7d1b17b05a0cd8 100644 (file)
@@ -55,7 +55,7 @@
 #define L4_PAGETABLE_ENTRIES    512
 #endif
  
-#define PAGE_SHIFT              L1_PAGETABLE_SHIFT
+#define PAGE_SHIFT              XC_PAGE_SHIFT
 #define PAGE_SIZE               (1UL << PAGE_SHIFT)
 #define PAGE_MASK               (~(PAGE_SIZE-1))
 
index 19bc4fad20e842f3fe906edebfc5316a34953f0d..3b695f61e2958317e70a1481e854afe1dd0d002c 100644 (file)
@@ -22,7 +22,9 @@ all: build
 build: $(TARGETS)
        $(MAKE) -C miniterm
        $(MAKE) -C cpuperf
+ifneq ($(XEN_TARGET_ARCH),ia64)
        $(MAKE) -C mbootpack
+endif
        $(MAKE) -C lomount
 
 install: build
index 46e2ba25b306d71d412a9ec7b2d1645297e7a78e..0756f656fc568c88ef9ccc41f5c764aa969b53e3 100644 (file)
@@ -242,7 +242,7 @@ static PyObject *pyxc_domain_getinfo(PyObject *self,
                                   "paused",    info[i].paused,
                                   "blocked",   info[i].blocked,
                                   "running",   info[i].running,
-                                  "mem_kb",    info[i].nr_pages*4,
+                                  "mem_kb",    info[i].nr_pages*(XC_PAGE_SIZE/1024),
                                   "cpu_time",  info[i].cpu_time,
                                   "maxmem_kb", info[i].max_memkb,
                                   "ssidref",   info[i].ssidref,
index 9c2663fbf0b46ee308b51534af7f1ab5f3ca1e73..f81dd722a4c6d73b236393df488c342c1dc608cb 100644 (file)
@@ -46,9 +46,6 @@
 /* EVTCHN_UNBIND: Unbind from the specified event-channel port. */
 #define EVTCHN_UNBIND _IO('E', 3)
 
-/* Size of a machine page frame. */
-#define PAGE_SIZE 4096
-
 /* Set the close-on-exec flag on a file descriptor.  Doesn't currently bother
  * to check for errors. */
 /*
index 654fb022c59d10a4a20d5e7608d0d2fa6cd32eed..705555c5107bd3efd45d1d8b7983e5ce76354ddc 100644 (file)
@@ -17,7 +17,6 @@ from XendError import XendError
 from XendLogging import log
 
 SIGNATURE = "LinuxGuestRecord"
-PAGE_SIZE = 4096
 PATH_XC_SAVE = "/usr/libexec/xen/xc_save"
 PATH_XC_RESTORE = "/usr/libexec/xen/xc_restore"
 
index 5a26724ce10aee3255fe298521b7d92d26c143e7..0d37659ce89e05e5e2d12cf0f871725367077b1c 100644 (file)
@@ -37,7 +37,7 @@
 /* ------[ Other required defines ]----------------------------------------*/
 
 /* Size of a machine page frame. */
-#define PAGE_SIZE 4096
+#define PAGE_SIZE XC_PAGE_SIZE
 
 #ifndef timersub /* XOPEN and __BSD don't cooperate well... */
 #define timersub(a, b, result)                                                \